class BufferedOutput(object):
    def __init__(self, inner_output, buffered_size=50):
        self.inner_output = inner_output
        self.buffered_size = buffered_size
        self.buffer_results = list()

    def dump(self, results):
        self.buffer_results += results
        if len(self.buffer_results) >= self.buffered_size:
            self.inner_output.dump(self.buffer_results)

    def done(self):
        self.inner_output.dump(self.buffer_results)